package com.feihong.yw189.adapter.Kuandai;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.view.View;
import android.widget.ImageView;

import com.feihong.yw189.R;
import com.feihong.yw189.model.Kaika.ChooseSimModel;
import com.holenzhou.pullrecyclerview.BaseRecyclerAdapter;
import com.holenzhou.pullrecyclerview.BaseViewHolder;

import java.util.List;

/**
 * Created by PVer on 2017/12/20.
 */

public class ChooseSimAdapter   extends BaseRecyclerAdapter<ChooseSimModel.DataBean.ListBean> {

    Activity  mcontext;
    private OnItemClickListener mOnItemClickListener;
    public ChooseSimAdapter(Context context, int layoutResId, List<ChooseSimModel.DataBean.ListBean> data) {
        super(context, layoutResId, data);
        mcontext= (Activity) context;
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener){
        mOnItemClickListener = onItemClickListener;
    }

    @Override
    protected void convert(BaseViewHolder holder, final ChooseSimModel.DataBean.ListBean item) {
        //可链式调用赋值
        SpannableString spannabletext = new SpannableString(item.getIccid_no());
        @SuppressLint("ResourceAsColor")
        ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.parseColor("#29a5ed"));
        spannabletext.setSpan(foregroundColorSpan, 13, item.getIccid_no().length() , Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
        spannabletext.setSpan(new RelativeSizeSpan(1.2f), 13, item.getIccid_no().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 0.5f表示默认

        holder.setText(R.id.tv_phonenum,spannabletext);
        ImageView  ivChoose= holder.getView(R.id.iv_choose);
        ivChoose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               /* Map<String,String> map=new HashMap<>();
                map.put("Iccid_no",item.getIccid_no());
                EventBus.getDefault().postSticky(map);
                mcontext.finish();*/
                //mOnItemClickListener.setOnItemCklickListener(item.getIccid_no(),item.getId());
            }
        });

    }


    public interface OnItemClickListener{
        void setOnItemCklickListener(String simNum,String simNumId);
    }
}
